package com.sgb.merchant.view.adapter;

import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.link.entity.merchant.EnrolInfoEntiy;
import com.sgb.merchant.R;
import com.swgk.core.util.DateUtils;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class EnrolListAdapter extends BaseQuickAdapter<EnrolInfoEntiy, BaseViewHolder> {
    boolean isSelf;//是否是个中心详情



    public void setSelf(boolean self) {
        isSelf = self;
    }

    public EnrolListAdapter(@Nullable @org.jetbrains.annotations.Nullable List<EnrolInfoEntiy> data) {
        super(R.layout.merchant_item_enrol_info,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, EnrolInfoEntiy item) {
        String name=item.getTenantName();
        if(!isSelf) {
            if (!TextUtils.isEmpty(name)) {
                StringBuilder stringBuilder = new StringBuilder(name);
                int length = name.length();
                String names = name.substring(length - 1, length);
                switch (item.getApplyUtype()) {
                    case 0:
                    case 2:
                        name = StringUtils.leftPad(names, length, "*");
                        break;
                    case 1:
                    case 3:
                        if (length > 12) {
                            name = stringBuilder.replace(3, length - 2, "****").toString();
                        } else {
                            name = stringBuilder.replace(3, length, "****").toString();
                        }
                        break;
                    default:
                        break;
                }
                helper.setText(R.id.tv_names, name);
            }
        }else{
            helper.setText(R.id.tv_names, name);
        }
               helper.setText(R.id.tv_time_info, DateUtils.stampToDay6(item.getCreateTime()));
       switch (item.getApplyUtype()){
           case 0:
               helper.setImageResource(R.id.iv_icon,R.mipmap.merchant_icon_person);
               break;
           case 1:
               helper.setImageResource(R.id.iv_icon,R.mipmap.merchant_icon_qiye);
               break;
           case 2:
               helper.setImageResource(R.id.iv_icon,R.mipmap.merchant_icon_teams);
               break;
           case 3:
               helper.setImageResource(R.id.iv_icon,R.mipmap.merchant_icon_zu);
               break;
       }
    }


}
